package com.mall.server.controller.sms;

import com.mall.model.domain.SmsFlashPromotionSession;
import com.mall.model.vo.CommonResult;
import com.mall.model.vo.SmsFlashPromotionSessionVo;
import com.mall.server.service.sms.SmsFlashPromotionSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * 获取全部可选场次及其数量
     */
    @GetMapping("/selectList")
    public CommonResult selectList(Integer flashPromotionId) {

        List<SmsFlashPromotionSessionVo> list = smsFlashPromotionSessionService.selectList(flashPromotionId);

        return CommonResult.success(list);
    }

    /**
     * 获取全部场次
     */
    @GetMapping("/list")
    public CommonResult list() {

        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.list();

        return CommonResult.success(list);
    }


    /**
     * 添加场次
     */
    @PostMapping("/create")
    public CommonResult saveFlash(@RequestBody SmsFlashPromotionSession flashPromotionSession) {

        smsFlashPromotionSessionService.saveFlash(flashPromotionSession);

        return CommonResult.success(null);
    }

    /**
     * 删除场次
     */
    @PostMapping("/delete/{id}")
    public CommonResult deleteFlash(@PathVariable("id") Integer id) {

        smsFlashPromotionSessionService.deleteFlash(id);

        return CommonResult.success(null);
    }

    /**
     * 修改启用状态
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable("id") Integer id, SmsFlashPromotionSession smsFlashPromotion) {

        smsFlashPromotionSessionService.updateFlash(id, smsFlashPromotion);

        return CommonResult.success(null);
    }

    /**
     * 修改场次
     */
    @PostMapping("/update/{id}")
    public CommonResult updateFlash(@PathVariable("id") Integer id, @RequestBody SmsFlashPromotionSession smsFlashPromotion) {

        smsFlashPromotionSessionService.updateFlash(id, smsFlashPromotion);

        return CommonResult.success(null);
    }

    /**
     * 获取活动详情
     */
    @GetMapping("/{id}")
    public CommonResult findById(@PathVariable("id") Integer id) {

        SmsFlashPromotionSession flashPromotion = smsFlashPromotionSessionService.findById(id);

        return CommonResult.success(flashPromotion);
    }


}
